<template>
    <div>
        <div class="head">
            <el-form inline :model="searchData"
                     label-width="150px"
                     size="small"
            >

                <el-form-item>
                    <el-input v-model="searchData.tableName" @keyup.enter.native="search"
                              placeholder="表名称">
                    </el-input>
                </el-form-item>

                <el-form-item>
                    <el-input v-model="searchData.tableComment" @keyup.enter.native="search"
                              placeholder="表说明">
                    </el-input>
                </el-form-item>


                <el-form-item>
                    <el-button icon="el-icon-delete" type="danger" @click="clearForm">重置</el-button>
                    <el-button plain type="primary" @click="search" icon="el-icon-search">搜索</el-button>
                </el-form-item>
            </el-form>


        </div>
        <div>
            <!-- 表 -->
            <el-table :data="tableData" border v-loading="loading">
                <el-table-column label="ID" align="center" width="100">
                    <template slot-scope="scope">{{ scope.row.tableId }}</template>
                </el-table-column>
                <el-table-column label="表名称" align="center">
                    <template slot-scope="scope">{{ scope.row.tableName }}</template>
                </el-table-column>
                <el-table-column label="表说明" align="center">
                    <template slot-scope="scope">{{ scope.row.tableComment }}</template>
                </el-table-column>
                <el-table-column label="实体" align="center">
                    <template slot-scope="scope">{{ scope.row.tableEntity }}</template>
                </el-table-column>

                <el-table-column label="创建时间" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">{{ scope.row.createTime | filterCtime}}</template>
                </el-table-column>

                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button plain size="mini" type="success"
                                   @click="genCode(scope.row.tableName)">生成代码
                        </el-button>
                    </template>
                </el-table-column>

            </el-table>

        </div>

    </div>
</template>

<script>
    import {table_list, gen_code} from "@/api/sysconfig"
    import moment from 'moment'

    export default {
        name: "gen-code",
        data() {
            return {
                loading: false,
                tableData: [],
                dateRange: [],
                formInline: {},
                searchData: {
                    tableName: "",
                    tableComment: ""
                }
            };
        },
        created() {
            this.getData();
        },
        methods: {
            //搜索
            search() {
                this.getData();
            },
            //重置搜索
            clearForm() {
                this.searchData = {};
                this.getData();
            },
            //生成代码
            genCode(tableName) {

                gen_code({tableName: tableName}).then(res => {
                    if (res.status === 200) {
                        this.$message.success(res.msg);
                    }
                })
            },


            /**
             * 获取数据
             */
            getData() {
                let params = {};
                params.tableName = this.searchData.tabelName;
                params.tableComment = this.searchData.tableComment;
                table_list(params).then(res => {
                    if (res.status === 200) {
                        this.tableData = res.data;
                        this.loading = false;
                    }

                })
            },
        },
        filters: {
            filterCtime(ctime) {
                // 过滤时间
                if (ctime) {
                    return moment(ctime).format("YYYY-MM-DD HH:mm:ss");
                } else {
                    return '暂无数据'
                }
            },
            filterShow(show) {
                if (show === 1) {
                    return '显示'
                } else {
                    return '不显示'
                }
            }
        }
    }
</script>

<style scoped>

</style>
